package com.dlc.felear.xiaoensale.utils;

import android.util.Log;

import com.dlc.felear.xiaoensale.deviceControlSf.HcSfControlUtil;
import com.dlc.felear.xiaoensale.factory.CmdSfList;

public class InitSfInfo {
    private static final String TAG="InitSfInfo";
    private HcSfControlUtil sfControl;
    private int maxSpeed=200;
    private int jjTime=10;
    private int addr;

    public InitSfInfo(HcSfControlUtil sfControl, int addr, int size) {
        this.sfControl = sfControl;
        this.addr = addr;
//        initSf(addr,size);
    }

    private void initSf(int size){
        //起始段序号
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0801,0x01));
        //终点段序号
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0802,size));
        //等待时间单位 0 ms 1 s
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0803,0x00));
        //暂停再启动运行方式 0 运行剩余段 1 再次从起始段开始
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0803,0x00));
        //位置指令 0 相对位置 1 绝对位置
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0804,0x01));
        //第1段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0808,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0809,jjTime));
        //第2段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x080D,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x080E,jjTime));
        //第3段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0812,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0813,jjTime));
        //第4段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0817,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0818,jjTime));
        //第5段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x081C,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x081D,jjTime));
        //第6段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0821,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0822,jjTime));
        //第7段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0826,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0827,jjTime));
        //第8段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x082B,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x082C,jjTime));
        //第9段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0830,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0831,jjTime));
        //第10段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0835,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0836,jjTime));
        //第11段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x083A,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x083B,jjTime));
        //第12段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x083F,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0840,jjTime));
        //第13段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0844,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0845,jjTime));
        //第14段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0849,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0850,jjTime));
        //第15段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x084E,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x084F,jjTime));
        //第16段
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0853,maxSpeed));
        sfControl.sendCmd(CmdSfList.sfWriteRegister(addr,0x0854,jjTime));
    }

    public void setPlus(int num, int puls) {
        try {
            Log.e(TAG,"sfControl="+puls);
            if(sfControl!=null){
                int regAdd=0x0801+(num*5);
                sfControl.sendCmd(CmdSfList.sfWrite32Register(addr, regAdd, puls));
            }

        }catch (Exception e){
            Log.e(TAG,e.getMessage());
        }
    }
}
